package so.shanku.essential.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import aym.util.json.JsonMap;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;
import so.shanku.essential.R;
import so.shanku.essential.app.MyApplication;
import so.shanku.essential.utils.ImageLoaderBitmapCallBack;
import so.shanku.essential.utils.StringUtil;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015/9/9.
 * 退货的商品列表
 */
public class ReturnProductOrderAdapter extends MyBaseAdapter {


	public ReturnProductOrderAdapter(Context context) {
		super(context);
	}

	public ReturnProductOrderAdapter(Context context, List<? extends Map<String, ?>> datas) {
		super(context, datas);
	}

//	{"ReturnAmout":1,"Path":"","ProductName":"杭州果来果趣7两9颗特惠包邮云南蒙自甜石榴9个装","ProductId":"17147",
//				"speStrName":"M "}
	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		ViewHolder viewHolder = null;
		if (view == null) {
			view = layoutInflater.inflate(R.layout.order_goods_item, viewGroup, false);
			viewHolder = new ViewHolder(view);
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) view.getTag();
		}
		JsonMap jsonMap = (JsonMap) datas.get(i);
		String pic_path = StringUtil.get_SImage(jsonMap.getStringNoNull("Path"));
		if (MyApplication.getInstance().getBitmapHashMap().containsKey(pic_path)) {
			viewHolder.iv_goods_logo.setImageBitmap((MyApplication.getInstance().getBitmapHashMap().get(pic_path)));
		} else {
			ImageLoader.getInstance().displayImage(pic_path, viewHolder.iv_goods_logo, MyApplication.getInstance().getDefaultOption(), new ImageLoaderBitmapCallBack());
		}
		viewHolder.tv_goods_name.setText(jsonMap.getStringNoNull("ProductName"));
		viewHolder.tv_goods_color.setText(jsonMap.getStringNoNull("speStrName"));
		viewHolder.tv_goods_price.setText(StringUtil.getFormatMoneyWithSign(jsonMap.getStringNoNull("ReturnCommission")));
		viewHolder.tv_goods_amount.setText("X"+jsonMap.getStringNoNull("ReturnAmout"));

		return view;
	}

	private class ViewHolder {
		@ViewInject(R.id.iv_goods_logo)
		private ImageView iv_goods_logo;
		@ViewInject(R.id.tv_goods_name)
		private TextView tv_goods_name;
		@ViewInject(R.id.tv_goods_color)
		private TextView tv_goods_color;
		@ViewInject(R.id.tv_goods_price)
		private TextView tv_goods_price;
		@ViewInject(R.id.tv_goods_amount)
		private TextView tv_goods_amount;

		public ViewHolder(View view) {
			ViewUtils.inject(this, view);
		}
	}
}
